/*
 * @Author: your name
 * @Date: 2021-06-16 17:11:58
 * @LastEditTime: 2021-06-17 10:58:15
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \consumeTask\market\setActivity.go
 */
package main

import (
	"context"
	"encoding/json"
	"log"

	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/elastic/bus"
	cards2 "git.900sui.cn/kc/rpcinterface/interface/elastic/cards"
	"github.com/streadway/amqp"
)

//设置活动
func main() {
	rpcShopCards := new(bus.Shop).Init()
	defer rpcShopCards.Close()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("market.log.setActivity"))
	log.Println(kcgin.AppConfig.String("market.queue.setActivity"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("market.queue.setActivity"), func(msg amqp.Delivery) {
		var args cards2.ArgsSetShopsActivity
		err := json.Unmarshal(msg.Body, &args)
		if err != nil {
			log.Fatalf("%v", err)
		}
		var reply bool
		err = rpcShopCards.SetShopsActivity(context.Background(), &args, &reply)
		if err != nil {
			utils.Logerr.Printf("设置活动错误，args:%s, err:%s", args, err)
		}
	})

	if err != nil {
		utils.Logerr.Printf("设置活动任务错误, err: %s", err.Error())
	}
}
